//
//  LayoutS9ViewController.m
//  OASDK_Works
//
//  Created by ChenJie on 3/19/20.
//  Copyright © 2020 Mist. All rights reserved.
//

#import "LayoutS9ViewController.h"

@interface LayoutS9ViewController ()

@property (nonatomic, strong) UIView *node1;
@property (nonatomic, strong) UIView *node2;
@property (nonatomic, strong) UIView *node22;
@property (nonatomic, strong) UIView *node3;
@property (nonatomic, strong) UIView *node4;

@end

@implementation LayoutS9ViewController

#pragma mark - ViewController lifecycle

- (instancetype)init {
    self = [super init];
    if (self) {
        self.layoutDirection = DirectionRow;
        self.layoutJustifyContent = JustifyContentFlexStart;
        self.layoutAlignItems = AlignItemsFlexStart;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = NSStringFromClass(self.class);
    
    //
    [self.layoutContainer addSubview:self.node1];
    [self.node1 addSubview:self.node2];
    [self.node2 addSubview:self.node22];
    [self.node1 addSubview:self.node3];
    [self.layoutContainer addSubview:self.node4];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
}

- (void)viewWillLayoutSubviews {
    [super viewWillLayoutSubviews];
}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    
    //
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

#pragma mark - Public methods

- (void)setupLayout:(OADLayout5 *)layout {
    
    //
    layout.marginLeft = 5;
    layout.marginTop = 15;
    layout.marginRight = 5;
    layout.marginBottom = 35;
    
    layout.width = 350;
    layout.height = 400;
    
    //
    OADLayout5 *node1 = [OADLayout5 new];
    node1.name = @"node1";
    
    node1.direction = DirectionColumn;
    
    node1.marginLeft = 10;
    node1.marginTop = 5;
    node1.marginRight = 0;
    node1.marginBottom = 5;
    
    node1.grow = 1;
    
    [layout addNode:node1];
    
    //
    OADLayout5 *node2 = [OADLayout5 new];
    node2.name = @"node2";
    
    node2.direction = DirectionColumn;
    
    node2.marginLeft = 5;
    node2.marginTop = 5;
    node2.marginRight = 5;
    node2.marginBottom = 5;
    
    node2.grow = 1;
    
    [node1 addNode:node2];
    
    //
    OADLayout5 *node22 = [OADLayout5 new];
    node22.name = @"node22";
    
    node22.direction = DirectionColumn;
    
    node22.marginLeft = 10;
    node22.marginTop = 15;
    node22.marginRight = 20;
    node22.marginBottom = 25;
    
    node22.width = 100;
    node22.height = 50;
    
    node22.grow = 1;
    
    [node2 addNode:node22];
    
    //
    OADLayout5 *node3 = [OADLayout5 new];
    node3.name = @"node3";
    
    node3.marginLeft = 10;
    node3.marginTop = 10;
    node3.marginRight = 10;
    node3.marginBottom = 10;
    
    node3.width = 40;
    node3.height = 50;
    
    [node1 addNode:node3];
    
    //
    OADLayout5 *node4 = [OADLayout5 new];
    node4.name = @"node4";
    
    node4.marginLeft = 10;
    node4.marginTop = 5;
    node4.marginRight = 10;
    node4.marginBottom = 5;
    
    node4.width = 40;
    node4.height = 50;
    
    [layout addNode:node4];
}

#pragma mark - Private methods



#pragma mark - Event response methods

- (void)buttonClicked:(UIButton *)button {
    NSLog(@"button clicked...");
}

#pragma mark - Deletate methods



#pragma mark - Setter



#pragma mark - Getter

- (UIView *)node1 {
    if (!_node1) {
        UIView *view = [UIView new];
        view.layoutName = NSStringFromSelector(_cmd);
        _node1 = view;
    }
    return _node1;
}

- (UIView *)node2 {
    if (!_node2) {
        UIView *view = [UIView new];
        view.layoutName = NSStringFromSelector(_cmd);
        _node2 = view;
    }
    return _node2;
}

- (UIView *)node22 {
    if (!_node22) {
        UIView *view = [UIView new];
        view.layoutName = NSStringFromSelector(_cmd);
        _node22 = view;
    }
    return _node22;
}

- (UIView *)node3 {
    if (!_node3) {
        UIView *view = [UIView new];
        view.layoutName = NSStringFromSelector(_cmd);
        _node3 = view;
    }
    return _node3;
}

- (UIView *)node4 {
    if (!_node4) {
        UIView *view = [UIView new];
        view.layoutName = NSStringFromSelector(_cmd);
        _node4 = view;
    }
    return _node4;
}

#pragma mark - Memory management

- (void)dealloc {
}

@end
